package com.qingchunlin.blogsystem.entity;

import com.qingchunlin.blogsystem.common.enums.BusinessStatus;
import lombok.Data;

@Data
public class Result<T> {
    private BusinessStatus businessStatus;
    private String errorMessage;
    private T data;

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setBusinessStatus(BusinessStatus.SUCCESS);
        result.setErrorMessage("");
        result.setData(data);
        return result;
    }
    public static <T> Result<T> failure(String errorMessage) {
        Result<T> result = new Result<>();
        result.setBusinessStatus(BusinessStatus.FAILURE);
        result.setErrorMessage(errorMessage);
        result.setData(null);
        return result;
    }
    public static <T> Result<T> failure(String errorMessage, T data) {
        Result<T> result = new Result<>();
        result.setBusinessStatus(BusinessStatus.FAILURE);
        result.setErrorMessage(errorMessage);
        result.setData(data);
        return result;
    }
}
